package com.ruoyi.app.config.result;

import com.ruoyi.common.core.constant.HttpStatus;

import java.util.Arrays;
import java.util.Optional;


/**
 * @title: ResultEnum
 * @Description: 返回结果
 */
public enum ResultEnum {

    /**
     * 操作异常
     */
    ERROR(HttpStatus.ERROR, "操作异常"),
    /**
     * 操作成功
     */
    SUCCESS(HttpStatus.SUCCESS, "操作成功"),
    LOGINCONTEXT_ERROR(HttpStatus.UNAUTHORIZED, "登录状态验证错误,请重新登录!"),
    PARAMETER_ERROR(-3, "参数错误！"),
    ;

    private final int val;
    private final String msg;

    ResultEnum(int val, String msg) {
        this.val = val;
        this.msg = msg;
    }

    public int val() {
        return this.val;
    }

    public String msg() {
        return this.msg;
    }

    public static final ResultEnum getByCode(int code) {
        return Optional.ofNullable(Arrays.stream(values()).filter(l -> code == l.val()).findFirst().get()).orElse(ERROR);
    }
}
